package com.cy.cykh.app.util

import android.app.Activity
import android.util.Log

import java.util.ArrayList

/**
 * Created by Administrator on 2018/5/4.
 */

class ActivityManagerUtil private constructor() {
    private val listAct = ArrayList<Activity>()//退出app使用
    private val listCurrAct = ArrayList<Activity>()//关闭多个使用

    val currentActivitySize: Int
        get() = listAct.size

    //application管理所有activity,暂不用广播
    fun addActivity(activity: Activity) {
        listAct.add(activity)
        Log.d("SJY", "Current Acitvity Size :$currentActivitySize")
    }

    fun removeActivity(activity: Activity) {
        listAct.remove(activity)
        activity.finish()
        Log.d("SJY", "Current Acitvity Size :$currentActivitySize")
    }

    fun exit() {
        for (activity in listAct) {
            activity.finish()
        }
    }

    //管理多个界面使用,不同于 管理所有界面
    fun addACT(activity: Activity) {
        listCurrAct.add(activity)
    }

    fun closeACT() {
        for (activity in listCurrAct) {
            activity.finish()
        }
        //清空数据
        listCurrAct.clear()
    }

    companion object {
        private var instance: ActivityManagerUtil? = null
            get() {
                if (field == null) {
                    field = ActivityManagerUtil()
                }
                return field
            }
        @Synchronized
        fun get(): ActivityManagerUtil{
            return instance!!
        }
    }

}
